package com.hnas.core.http;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class HttpPara  implements java.io.Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -7409193509190233801L;
	private String serverIp;
	private int serverport = 80;
	private String url = "";
	private Map<String, String> paras = new HashMap<String, String>();

	public String getServerIp() {
		return serverIp;
	}

	public void setServerIp(String serverIp) {
		this.serverIp = serverIp;
	}

	public int getServerport() {
		return serverport;
	}

	public void setServerport(int serverport) {
		this.serverport = serverport;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Map<String, String> getParas() {
		return paras;
	}

	public void setParas(Map<String, String> paras) {
		this.paras = paras;
	}

//	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		for(String key:this.paras.keySet()){
			String value= this.paras.get(key);
			if (sb.length()>0)
				sb.append("&");
			sb.append(key).append(":").append(value);
		}
		return sb.toString();
	}
	public String formUrl(){
		StringBuffer sb = new StringBuffer();
		for (Entry entry : this.getParas().entrySet()){
			if (sb.length()>0)
				sb.append("&");
			sb.append(entry.getKey()).append("=").append(entry.getValue());
		}
		String url1 = "http://"+this.serverIp+":"+this.serverport+this.url;
		if (sb.length()>0)
			return url1+"?"+sb;
		return url1;
	}
}
